package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.provider.model.domain.TurnUsersLt;
import com.csun.cmny.provider.model.dto.ice.TurnUsersLtDto;
import com.csun.cmny.provider.model.dto.ice.TurnUsersLtQueryDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.TurnUsersLtService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020-07-17 16:53
 * @Description:
 */
@RestController
@RequestMapping(value = "/turn", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class TurnUsersLtController {

    @Resource
    private TurnUsersLtService turnUsersLtService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 分页查询turn users信息列表
     *
     * @param turnUsersLtQueryDto
     *
     * @return
     */
    @RequestMapping(value = "/queryListWithPage", method = RequestMethod.POST)
    public Wrapper queryListWithPage(@RequestBody TurnUsersLtQueryDto turnUsersLtQueryDto) {

        List<TurnUsersLt> turnUsersLtList = turnUsersLtService.queryListWithPage(turnUsersLtQueryDto);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                new PageInfo<>(turnUsersLtList));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Wrapper save(@RequestBody TurnUsersLtDto turnUsersLtDto) {

        Integer result = turnUsersLtService.save(turnUsersLtDto);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE,
                    cmnyMessageSource.getMessage("operation.failed",null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null), result);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper delete(@RequestBody TurnUsersLt turnUsersLt) {

        Integer result = turnUsersLtService.delete(turnUsersLt);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE,
                    cmnyMessageSource.getMessage("operation.failed",null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null), result);
    }

}
